package com.JZ.QM.common.utils;

import org.apache.http.HttpStatus;

import java.util.HashMap;
import java.util.Map;

/**
 *
 * @author lyp
 * @email lyp@gmail.com
 * @date 2020-06-14 11:19:34
 */
public class CommonResult extends HashMap<String, Object> {
    private static final long serialVersionUID = 1L;

    public CommonResult() {
        put("code", 200);
        put("msg", "请求成功");
    }

    public static CommonResult error() {
        return error(HttpStatus.SC_INTERNAL_SERVER_ERROR, "未知异常，请联系管理员");
    }

    public static CommonResult error(String msg) {
        return error(HttpStatus.SC_INTERNAL_SERVER_ERROR, msg);
    }

    public static CommonResult error(int code, String msg) {
        CommonResult result = new CommonResult();
        result.put("code", code);
        result.put("msg", msg);
        return result;
    }

    public static CommonResult success(String msg) {
        CommonResult result = new CommonResult();
        result.put("msg", msg);
        return result;
    }

    public static CommonResult success(Map<String, Object> map) {
        CommonResult result = new CommonResult();
        result.putAll(map);
        return result;
    }

    public static CommonResult success() {
        return new CommonResult();
    }

    public CommonResult put(String key, Object value) {
        super.put(key, value);
        return this;
    }

    public  Integer getCode() {
        return (Integer) this.get("code");
    }

    public String getMsg(){return (String) this.get("msg");}

}